﻿using Architecture.Repository.Interface;
using Architeture.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.Domain.Service
{
    public class AllPicService : IAllPicService
    {
        protected readonly IAllPicRepsitory allPicRepsitory;

        public AllPicService(IAllPicRepsitory allPicRepsitory)
        {
            this.allPicRepsitory = allPicRepsitory;
        }

        public async Task<int> AddPic(AllPic a)
        {
            var listcount = (await allPicRepsitory.GetAllAsync()).Count(x => x.PicType == a.PicType);
            if (listcount > 8)
            {
                return -1;
            }
            else
            {
                return await allPicRepsitory.AddAsync(a);
            }

        }

        public async Task<int> DeletePic(int id)
        {
            return await allPicRepsitory.Delete(id);
        }

        public async Task<List<AllPic>> GetProductinspectionreport(string name, int gid)
        {
            return (await allPicRepsitory.GetAllAsync()).Where(x => x.PicType == name && x.GoodsInfoid == gid).ToList();
        }
    }
}
